package com.spring.learn.config;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

/**
 * Created by baiguantao on 2018/1/4.
 */

@Aspect
@Component
public class AspectJAnnotationDemo {

    @Pointcut("execution(* com.spring.learn.service.*.*(..))")
    public void pointcut(){

    }

    @Around("pointcut()")
    public Object profile(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("------------");
        StopWatch sw = new StopWatch(getClass().getSimpleName());
        try {
            sw.start(pjp.getSignature().getName());
            return pjp.proceed();
        } finally {
            sw.stop();
            System.out.println(sw.prettyPrint());
        }
    }

    @Before(value = "pointcut()")
    public void Before(){
        System.out.println("before....");
    }
}
